// Kony

#pragma once

#include "CoreMinimal.h"
#include "BaseAbilityTypes.h"
#include "GameFramework/Actor.h"
#include "BaseProjectile.generated.h"

class USphereComponent;
class UProjectileMovementComponent;
class UNiagaraSystem;

//投射物Actor
UCLASS()
class GASC_HUANLING_API ABaseProjectile : public AActor
{
	GENERATED_BODY()
	
public:	
	ABaseProjectile();

	//球体移动组件
	UPROPERTY(VisibleAnywhere)
	TObjectPtr<UProjectileMovementComponent> ProjectileMovement;
	//伤害效果参数
	UPROPERTY(BlueprintReadWrite ,meta = (ExposeOnSpawn = true))
	FDamageEffectParams	DamageEffectParams;
	//场景组件指针，用于无目标时释放技能创建的空组件 清理回收用的变量 加上UPROPERTY 当投射物清理时UE会自动清理这个变量
	UPROPERTY()
	TObjectPtr<USceneComponent> HomingTargetSceneComponent;
	
	//设置自动爆炸定时器
	UFUNCTION(BlueprintCallable)
	void SetAutoExplodeTimer(float ExplodeTime);
	//设置只碰撞指定目标
	UFUNCTION(BlueprintCallable)
	void SetOnlyHitSpecificTarget(AActor* SpecificTarget);
	
	
protected:
	virtual void BeginPlay() override;
	virtual void Destroyed() override;
	//攻击命中时 触发音效等
	UFUNCTION(BlueprintCallable)
	virtual void OnHit();
	//自动爆炸函数
	void AutoExplode();
	//处理碰撞函数
	UFUNCTION()
	virtual void OnSphereOverlap(UPrimitiveComponent* OverlappedComponent,AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
	//球形碰撞体积
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
	TObjectPtr<USphereComponent> Sphere;
	//判断验证是否允许触发重叠碰撞
	bool IsValidOverlap(AActor* OtherActor);
	
	//持续循环声音
	UPROPERTY(EditAnywhere)
	TObjectPtr<USoundBase> LoopingSound;
	//持续循环声音组件 用于控制关闭销毁等
	UPROPERTY()
	TObjectPtr<UAudioComponent> LoopingSoundComponent;
	
	//用于客户端判断是否已经碰撞
	bool bHit = false;

private:
	//生命周期 用于持续时间消失
	UPROPERTY(EditDefaultsOnly)
	float LifeTime = 3.0f;
	
	//碰撞影响效果
	UPROPERTY(EditAnywhere)
	TObjectPtr<UNiagaraSystem> ImpactEffect;
	//碰撞声音
	UPROPERTY(EditAnywhere)
	TObjectPtr<USoundBase> ImpactSound;
	//自动爆炸定时器句柄
	FTimerHandle AutoExplodeTimerHandle;
	//只碰撞指定目标
	bool bOnlyHitSpecificTarget = false;
	//指定碰撞目标
	UPROPERTY()
	TObjectPtr<AActor> SpecificTarget;
};
